package com.study.jdbc.junit;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import org.junit.Test;

import com.study.jdbc.utils.C3P0Util;

/**
* @Name: C3P0UtilTest
* @Description: C3P0数据源工具测试类
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-19 上午10:40:50 
* @Version: V1.0
 */
public class C3P0UtilTest {
	
	@Test
	public void test() {
		Connection con = null ;
		Statement s = null ;
		ResultSet rs = null ;
		try {
			//获取数据库连接对象
			con = C3P0Util.getConnection() ;
			System.out.println(con.getClass()); //class com.mchange.v2.c3p0.impl.NewProxyConnection
			String sql = "select id, name, price, detail, pic, createtime from tb_items ; " ;
			s = con.createStatement() ;
			rs = s.executeQuery(sql) ;
			while(rs.next()) {
				System.out.println("===================================");
				System.out.println(rs.getInt("id"));
				System.out.println(rs.getString("name"));
				System.out.println(rs.getFloat("price"));
				System.out.println(rs.getString("detail"));
				System.out.println(rs.getString("pic"));
				System.out.println(rs.getDate("createtime"));
			}
		} catch (Exception e) {
			e.printStackTrace() ;
		} finally {
			//释放资源
			C3P0Util.close(con, s, rs) ;
		}
	}

}
